package com.ruoyi.zhike.controller.sms;

import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.zhike.db.domain.SmsTemplateInfo;
import com.ruoyi.zhike.system.service.ISmsTemplateInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.zhike.wrapper.SmsTemplateInfoWrapper;

/**
 * 短信模板Controller
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/sms/templateInfo")
public class SmsTemplateInfoController extends BaseController
{
    @Autowired
    private ISmsTemplateInfoService smsTemplateInfoService;

    /**
    *
    */
    @GetMapping("/extData")
    public AjaxResult extData() {
        JSONObject returnData = new JSONObject();

        return AjaxResult.success(returnData);
    }

    /**
     * 查询短信模板列表
     */
    @RequiresPermissions("sms:templateInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(SmsTemplateInfo smsTemplateInfo)
    {
        startPage();
        List<Map<String, Object>> list = smsTemplateInfoService.selectSmsTemplateInfoListMap(smsTemplateInfo);
        list = new SmsTemplateInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出短信模板列表
     */
    @RequiresPermissions("sms:templateInfo:export")
    @Log(title = "短信模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsTemplateInfo smsTemplateInfo)
    {
        List<SmsTemplateInfo> list = smsTemplateInfoService.selectSmsTemplateInfoList(smsTemplateInfo);
        ExcelUtil<SmsTemplateInfo> util = new ExcelUtil<SmsTemplateInfo>(SmsTemplateInfo.class);
        util.exportExcel(response, list, "短信模板数据");
    }

    /**
     * 获取短信模板详细信息
     */
    @RequiresPermissions("sms:templateInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smsTemplateInfoService.selectSmsTemplateInfoById(id));
    }

    /**
     * 新增短信模板
     */
    @RequiresPermissions("sms:templateInfo:add")
    @Log(title = "短信模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsTemplateInfo smsTemplateInfo)
    {
        return toAjax(smsTemplateInfoService.insertSmsTemplateInfo(smsTemplateInfo));
    }

    /**
     * 修改短信模板
     */
    @RequiresPermissions("sms:templateInfo:edit")
    @Log(title = "短信模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsTemplateInfo smsTemplateInfo)
    {
        return toAjax(smsTemplateInfoService.updateSmsTemplateInfo(smsTemplateInfo));
    }

    /**
     * 删除短信模板
     */
    @RequiresPermissions("sms:templateInfo:remove")
    @Log(title = "短信模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsTemplateInfoService.deleteSmsTemplateInfoByIds(ids));
    }
}
